package com.sali.utils;

/**
 * @author: sali
 * @date: 2024/7/16 21:27.
 * @version: 1.0
 */
public class IpUtil {


    private static final long PART1 = 0xff000000;
    private static final long PART2 = 0xff0000;
    private static final long PART3 = 0xff00;
    private static final long PART4 = 0xff;

    /**
     * 数值IP转字符串IP,只支持IPV4
     */
    public static String ip2Str(long ip) {
        String ipStr = String.valueOf((ip & PART1) >> 24);
        ipStr += "." + ((ip & PART2) >> 16);
        ipStr += "." + ((ip & PART3) >> 8);
        ipStr += "." + ((ip & PART4));

        return ipStr;
    }

}
